package com.weixin.project.Service;

import com.weixin.project.Common.Enum.ReportStatus;
import com.weixin.project.Dao.InformReportDao;
import com.weixin.project.Entity.InformReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class ReportService {
    @Value("10")
    private Integer pageSize;
    @Autowired
    private InformReportDao reportDao;
    public void storeReport(InformReport record){
        reportDao.save(record);
    }

    public Page<InformReport> findQuestionReports(Integer page){
        Pageable pageable = PageRequest.of(page, pageSize);
        return reportDao.getInformRecordsByTypeAndReportStatus(1, ReportStatus.TO_BE_PROCESSED, pageable);
    }

    public Page<InformReport> findVideoReports(Integer page){
        Pageable pageable = PageRequest.of(page, pageSize);
        return reportDao.getInformRecordsByTypeAndReportStatus(2, ReportStatus.TO_BE_PROCESSED, pageable);
    }

    public void refuseReport(Integer reportId){
        Optional<InformReport> reportOp = reportDao.findById(reportId);
        if (!reportOp.isPresent()){
            System.out.println("ERROR: Report::" + reportId + " not exists!");
        }
        InformReport report = reportOp.get();
        report.setReportStatus(ReportStatus.REFUSED);
        storeReport(report);
    }
}
